package com.wenbo.ocr.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Author wenbo
 * @Date 2023/10/18 22:04
 **/
public class LogUtils {
    private LogUtils() {
    }

    public static void printMessage(String message, Throwable t, LogUtils.Level level, String className) {
        Logger logger = LoggerFactory.getLogger(className);
        message = t != null && message == null ? t.getMessage() : message;
        switch(level) {
            case DEBUG:
                logger.debug(message, t);
                break;
            case INFO:
                logger.info(message, t);
                break;
            case ERROR:
                logger.error(message, t);
                break;
            default:
                logger.error("Unsupport log level");
        }

    }

    public static void printMessage(String message, LogUtils.Level level, String className) {
        printMessage(message, (Throwable)null, level, className);
    }

    public static void printMessage(String message, Throwable t, LogUtils.Level level) {
        StackTraceElement[] stack = (new Throwable()).getStackTrace();
        printMessage(message, t, level, stack[stack.length > 1 ? 1 : 0].getClassName());
    }

    public static void printMessage(String message, LogUtils.Level level) {
        StackTraceElement[] stack = (new Throwable()).getStackTrace();
        printMessage(message, (Throwable)null, level, stack[stack.length > 1 ? 1 : 0].getClassName());
    }

    public static void printMessage(String message) {
        StackTraceElement[] stack = (new Throwable()).getStackTrace();
        printMessage(message, LogUtils.Level.INFO, stack[stack.length > 1 ? 1 : 0].getClassName());
    }

    public static enum Level {
        DEBUG,
        INFO,
        ERROR;

        private Level() {
        }
    }
}
